package com.rainfull.ui;

import java.util.List;

import com.rainfull.core.IRUIAPNotify;
import com.rainfull.core.RAPMgr;
import com.rainfull.ui.RUIAccount.RUIRegLogin;

import android.app.Activity;
import android.content.Intent;
import android.net.NetworkInfo;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.FrameLayout.LayoutParams;

public class RUIApEnable extends Activity  implements OnClickListener, IRUIAPNotify 
{
	private main m_mainActive = null;
	private RAPMgr m_APMgr = null;
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {    	 
    	super.onCreate(savedInstanceState);  
    	setContentView(R.layout.ap_enable); 
    	m_mainActive = (main)this.getParent();
    	
    	LinearLayout ll = (LinearLayout) findViewById(R.id.ap_enable_ll_1);
        ll.setLayoutParams(new LayoutParams(m_mainActive.getScreenWidth(), 
        		LayoutParams.FILL_PARENT));
        Button btnEnable = (Button) findViewById(R.id.ap_enable_btn_wifi_enable);
        btnEnable.setOnClickListener(this);
        m_APMgr = new RAPMgr(this, this);
        
    }
    public boolean onKeyDown(int keyCode, KeyEvent event) 
	{
		return false;
	}
	public void onClick(View v) 
	{
		int nClickId = v.getId();
		if (nClickId == R.id.ap_enable_btn_wifi_enable)
		{			
			new RUIApEnableTask().execute(null);
			m_mainActive.changeTabView(RUIApEnable.class, RUIApList.class);			
		}    	
	}
	public void onApConnStateChange(NetworkInfo networkInfo, String strBSSID) {
		// TODO Auto-generated method stub
		
	}
	public void onScanResult(List<ScanResult> aplist) {
		// TODO Auto-generated method stub
		
	}
	public void onWifiStateChanged(int nState) 
	{
    	if (nState == WifiManager.WIFI_STATE_ENABLED ||
    		nState == WifiManager.WIFI_STATE_ENABLING)
    	{
    		m_mainActive.changeTabView(RUIApEnable.class, RUIApList.class);
    	}
	}
	
    //登陆注册接口
	public class RUIApEnableTask extends AsyncTask
	{
		@Override
		protected Object doInBackground(Object... param) 
		{
			m_APMgr.setWifiState(true);
			return null;
		}
	}
	
}
